Attackers often use SSH backdoors to gain or maintain unauthorized access to a system. Effective mitigation requires identifying unauthorized connections, eliminating rogue access points, and securing the SSH service to prevent recurrence.
List Current Sessions:
who
Inspect SSH Connections:
ss -t | grep ssh
Purpose:
Determine which IPs are connected and if there are unauthorized sessions.
List All Users:
cat /etc/passwd
Identify Suspicious Accounts:
Look for unfamiliar usernames.
Remove Unauthorized Accounts:
userdel -r [USERNAME]
Example:
userdel -r backdoor_user
Purpose:
Prevents attackers from reconnecting using rogue accounts.
Edit the SSH Configuration File:
nano /etc/ssh/sshd_config
Apply the Following Changes:
Restrict SSH Access to Specific Users:
AllowUsers valid_user
Disable Root Login:
PermitRootLogin no
Restart SSH Service:
systemctl restart sshd
Purpose:
Limits SSH access to known users and reduces the attack surface.
Review Authentication Logs:
cat /var/log/auth.log | grep "Accepted"
Purpose:
Detect unauthorized login attempts and successful logins.
Audit User Accounts Regularly:
cat /etc/passwd
Confirm that no unauthorized accounts have been added.
Monitor Logs: Continuously review logs for suspicious activity:
tail -f /var/log/auth.log
Test Configuration Changes: Ensure legitimate users can still connect.
Immediate Actions:
Disconnect unauthorized sessions.
Remove rogue accounts or SSH keys.
Secure the System:
Restrict SSH access to trusted users.
Disable unnecessary privileges like root login.
Ongoing Monitoring:
Regularly review logs and audit user accounts.
Stay vigilant for new access attempts or anomalies.
Key Idea: Mitigation of SSH backdoors involves detecting unauthorized activity, neutralizing access points, and securing configurations to prevent recurrence.